#!/bin/bash

license_type=$1

if [ -z $license_type ]; then
    echo "$0 <type>"
    exit 1
fi

echo $license_type

if [[ $license_type == "ptmc" ]]; then
    curl -sS -k  https://10.40.0.9:38080/cepoPenetrant/api/license/getLicenseKey  -o ptmc.key
    java -cp lib/*:target/license-utils-1.0-SNAPSHOT.jar com.leozhang.app.PTMCLicenseGenerator -c "张成飞" -i ptmc.key -o ptmc-license.lic
    curl -sS -k -X POST https://10.40.0.9:38080/cepoPenetrant/api/license/uploadLicense \
         -H "Content-type: application/json;charset=UTF-8" \
         -d "{\"content\":\"$(cat ptmc-license.lic)\"}" | echo -e "$(cat -)\n"
    rm -rf ptmc.key ptmc-license.lic
    echo "PTMC is OK now!!!"
elif [[ $license_type == "cr" ]]; then
    curl -sS -k https://10.40.0.99:38080/api/license/getLicenseKey -o cr.key
    java -cp lib/*:target/license-utils-1.0-SNAPSHOT.jar com.leozhang.app.CRLicenseGenerator -u 30000 -c "张成飞" -i cr.key -o cr-license.lic
    curl -sS -k -X POST https://10.40.0.99:38080/api/license/uploadLicense \
         -H "Content-type: application/json;charset=UTF-8" \
         -d "{\"content\":\"$(cat cr-license.lic)\"}" | echo -e "$(cat -)\n"
    rm -rf cr.key cr-license.lic
    echo "CR is OK now!!!"
fi
